package com.bit.bit_forum.controller;

import com.bit.bit_forum.common.AppResult;
import com.bit.bit_forum.model.Board;
import com.bit.bit_forum.service.IBoardService;
import io.swagger.annotations.Api;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 板块接口
 */
@Api("板块接口")
@RequestMapping("/board")
@RestController
@Slf4j
public class BoardController {
    //从配置文件中读取,自定义值:9
    @Value("${forum.index.board-num:9}")
    private Integer indexBoardNum;
    @Autowired
    private IBoardService boardService;

    /**
     * 获取板块首页列表
     * @param
     * @return
     */
    @RequestMapping("/topList")
    public AppResult<List<Board>> selectByNum(){
        log.info("首页板块个数wield: "+ indexBoardNum);
        List<Board> boards = boardService.selectByNum(indexBoardNum);
        if(boards==null){
            boards = new ArrayList<>();
        }
        //返回结果:
        return AppResult.success(boards);
    }

    @RequestMapping("/getById")
    public AppResult getById(@RequestParam("id") @NonNull Long id){
        return AppResult.success(boardService.getById(id));
    }
}
